<?php

class WSB_Auth_Adapter_Frontend implements Zend_Auth_Adapter_Interface
{

	/**
	 * @var string
	 */
	private $_username;

	/**
	 * @var string
	 */
	private $_password;

	/**
	 * @param string $username
	 * @param string $password
	 */
	public function __construct($username, $password)
	{
		if (!is_string($username)) {
			throw new Zend_Exception("Option '$username' is required to be a string");
		}
		if (!is_string($password)) {
			throw new Zend_Exception("Option '$password' is required to be a string");
		}
		$this->_username = $username;
		$this->_password = $password;
	}

    /**
     * Authenticates the username and password given
     *
     * @return Zend_Auth_Result
     */
    public function authenticate()
    {
    	$table = new Member_Model_DbTable_Feuser();
    	$select = $table->select();
        $select->where('username=?', $this->_username);
        $select->where('password=?', $this->_password);
        $select->where('hidden=?', 0);
        $select->where('deleted=?', 0);
    	$feuser = $table->fetchRow($select);
        if($feuser instanceof Member_Model_DbTable_Feuser_Row) {
			if(intval($feuser->id) > 0) {
				return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $feuser);
			}
		}
		return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
    }

}
